import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-11-13
 * Time: 17:54
 */
public class CardDemo {
    private static final String[] SUIT = {"♦", "♣", "♥", "♠"};

    //初始化一副扑克牌
    public static List<Card> buyCard() {
        List<Card> buyCard = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(CardDemo.SUIT[i], j);
                buyCard.add(card);
            }
        }
        return buyCard;
    }

    //洗牌
    public static void shuffle(List<Card> buyCard) {
        Random random = new Random();
        for (int i = buyCard.size() - 1; i > 0; i--) {
            int ran = random.nextInt(i);
            Card tmp = buyCard.get(i);
            buyCard.set(i, buyCard.get(ran));
            buyCard.set(ran, tmp);
        }
    }

    //打印扑克牌信息
    public static void display(List<Card> buyCard) {
        int count = 0;
        for (int i = 0; i < buyCard.size(); i++) {
            System.out.printf("%-3s ", buyCard.get(i));
            count++;
            if(count % 13 == 0 || i == buyCard.size() - 1) {
                System.out.println();
            }
        }
    }

    public static void main(String[] args) {
        List<Card> buyCard = buyCard();
        System.out.println("刚买来的牌：");
        display(buyCard);
        //System.out.println(buyCard);
        shuffle(buyCard);
        System.out.println("洗过的牌；");
        display(buyCard);

        //分牌,三个玩家，每个玩家轮流摸最上面的牌，摸5轮
        List<List<Card>> hand = new ArrayList<>();
        hand.add(new ArrayList<>());
        hand.add(new ArrayList<>());
        hand.add(new ArrayList<>());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hand.get(j).add(i, buyCard.remove(0));
            }
        }

        System.out.println("剩下的牌：");
        display(buyCard);
        System.out.println("一号玩家的牌：");
        System.out.println(hand.get(0));
        System.out.println("二号玩家的牌：");
        System.out.println(hand.get(1));
        System.out.println("三号玩家的牌：");
        System.out.println(hand.get(2));
    }
}
